package com.yhj.wchat.service.impl;



import com.yhj.wchat.entity.po.UserContactNew;
import com.yhj.wchat.entity.po.UserInfo;
import com.yhj.wchat.entity.query.PageSize;
import com.yhj.wchat.entity.query.SimplePage;
import com.yhj.wchat.entity.query.UserContactNewQuery;
import com.yhj.wchat.entity.vo.PaginationResultVO;
import com.yhj.wchat.mapper.UserContactNewMapper;
import com.yhj.wchat.service.UserContactNewService;
import com.yhj.wchat.utils.StringTools;
import io.swagger.models.auth.In;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;


/**
 *  业务接口实现
 */
@Service("userContactNewService")
public class UserContactNewServiceImpl implements UserContactNewService {

	@Resource
	private UserContactNewMapper<UserContactNew, UserContactNewQuery> userContactNewMapper;

	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<UserContactNew> findListByParam(UserContactNewQuery param) {
		return this.userContactNewMapper.selectList(param);
	}

	/**
	 * 根据条件查询列表
	 */
	@Override
	public Integer findCountByParam(UserContactNewQuery param) {
		return this.userContactNewMapper.selectCount(param);
	}

	/**
	 * 分页查询方法
	 */
	@Override
	public PaginationResultVO<UserContactNew> findListByPage(UserContactNewQuery param) {
		int count = this.findCountByParam(param);
		int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

		SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
		param.setSimplePage(page);
		List<UserContactNew> list = this.findListByParam(param);
		PaginationResultVO<UserContactNew> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
		return result;
	}

	/**
	 * 新增
	 */
	@Override
	public Integer add(UserContactNew bean) {
		return this.userContactNewMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Integer addBatch(List<UserContactNew> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.userContactNewMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或者修改
	 */
	@Override
	public Integer addOrUpdateBatch(List<UserContactNew> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.userContactNewMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 多条件更新
	 */
	@Override
	public Integer updateByParam(UserContactNew bean, UserContactNewQuery param) {
		StringTools.checkParam(param);
		return this.userContactNewMapper.updateByParam(bean, param);
	}

	/**
	 * 多条件删除
	 */
	@Override
	public Integer deleteByParam(UserContactNewQuery param) {
		StringTools.checkParam(param);
		return this.userContactNewMapper.deleteByParam(param);
	}

	/**
	 * 根据UserIdAndContactId获取对象
	 */
	@Override
	public UserContactNew getUserContactNewByUserIdAndContactId(String userId, String contactId) {
		return this.userContactNewMapper.selectByUserIdAndContactId(userId, contactId);
	}

	/**
	 * 根据UserIdAndContactId修改
	 */
	@Override
	public Integer updateUserContactNewByUserIdAndContactId(UserContactNew bean, String userId, String contactId) {
		return this.userContactNewMapper.updateByUserIdAndContactId(bean, userId, contactId);
	}

	/**
	 * 根据UserIdAndContactId删除
	 */
	@Override
	public Integer deleteUserContactNewByUserIdAndContactId(String userId, String contactId) {
		return this.userContactNewMapper.deleteByUserIdAndContactId(userId, contactId);
	}

	@Override
	public List<String> getContactUsers(String userId, Integer fex) {
		return userContactNewMapper.getContactUsers(userId,fex);
	}
}